package com.kingland.Gordon.service;

import com.kingland.Gordon.mapper.UserModelMapper;
import com.kingland.Gordon.model.UserModel;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;


/**
 * @author ZL
 */
@Service
public class UserServiceImpl implements  UserService{
    private final UserModelMapper userModelMapper;
    private final PasswordEncoder passwordEncoder;

    public  UserServiceImpl(UserModelMapper userModelMapper, PasswordEncoder passwordEncoder){
        this.userModelMapper = userModelMapper;
        this.passwordEncoder = passwordEncoder;
    }

    @Override
    public UserModel addUser(UserModel userModel) {
        userModel.setPassword(this.passwordEncoder.encode(userModel.getPassword()));
        this.userModelMapper.insert(userModel);
        return userModel;
    }

}
